package cn.fws.meap.community.web;

import java.util.List;

import cn.fws.framework.utils.StringUtils;
import cn.fws.meap.community.vo.ReplyListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.fws.meap.community.entity.Reply;
import cn.fws.meap.community.service.IReplyService;
import cn.fws.framework.web.contoller.BaseController;
import cn.fws.framework.web.page.PagingResult;
import cn.fws.framework.web.contoller.JsonResponse;

/**
 * 回复 信息操作处理
 * 
 * @author chenkh
 * @date 2019-03-07
 */
@RestController
@RequestMapping("/meap/reply")
@Api(tags = "回复 信息操作处理")
public class ReplyController extends BaseController{

	@Autowired
	private IReplyService replyService;

	private boolean flag;//这个标记是一级回复的方法还是二级回复的方法

	
	/**
	 * 查询回复列表
	 */
	//@RequiresPermissions("meap:reply:list")
	@ApiOperation(value = "查询回复列表")
	@PostMapping("/list")
	public PagingResult<Reply> list(Reply reply){
		startPage();
        List<Reply> list = replyService.selectList(reply);
		return getPagingResult(list);
	}
	
	/**
	 * 新增保存回复
	 */
	//@RequiresPermissions("meap:reply:add")
	@ApiOperation(value = "新增保存回复")
	@ApiImplicitParam(name = "reply", value = "新增保存回复",dataType = "Reply")
	@PostMapping("/add")
	public JsonResponse addSave(Reply reply)	{
		if(StringUtils.isEmpty(reply.getArticleId())){
			return JsonResponse.error("400","文章id不能为空");
		}else if(StringUtils.isEmpty(reply.getOpenid())){
			return JsonResponse.error("400","用户id不能为空");
		}else if(StringUtils.isEmpty(reply.getReplyMsg())){
			return JsonResponse.error("400","内容不能为空");
		}
        System.out.println("查看回复对象的is_delete"+reply.toString());
		return toAjax(replyService.insert(reply));
	}

	/**
	 * 修改保存回复
	 */
	//@RequiresPermissions("meap:reply:edit")
	@ApiOperation(value = "修改保存回复")
	@ApiImplicitParam(name = "reply", value = "修改保存回复",dataType = "Reply")
	@PutMapping("/edit")
	public JsonResponse editSave(Reply reply)	{
		return toAjax(replyService.update(reply));
	}
	
	/**
	 * 删除回复
	 */
	//@RequiresPermissions("meap:reply:remove")
	@ApiOperation(value = "删除回复")
	@ApiImplicitParam(name = "ids", value = "根据id删除回复",dataType = "String")
	@DeleteMapping( "/remove")
	public JsonResponse remove(@RequestBody String ids)	{
		return toAjax(replyService.deleteByIds(ids));
	}

	/** 文章回复分页查询 */
	@ApiOperation(value = "查询文章详情回复")
	@PostMapping("/getArticleReply")
	public PagingResult<ReplyListVo> getArticleReply(String articleId,String openId){
		 flag =false;
		startPage();
		List<ReplyListVo> articleReply = replyService.getArticleReply(articleId,openId,flag);
		return getPagingResult(articleReply);
	}

    /** 二级评论 */
	@ApiOperation(value = "文章中的二级评论")
	@PostMapping("/getMoreReply")
	public PagingResult<ReplyListVo> getMoreReply(String replyId,String openId){
		 flag =true;
		startPage();
		List<ReplyListVo> articleReply = replyService.getArticleReply(replyId,openId,flag);
		return getPagingResult(articleReply);
	}



	
}
